package test;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.*;

public class MsgProducer {

	private String queueName = "org.lsda.jobs";

	private String url = "tcp://localhost:61616";

	private String userName = "lsda";

	private String password = "admin";

	private MessageProducer msgProd = null;

	public MsgProducer() {
	}

	public void SendMsg() {
		ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
				userName, password, url);
		Connection connection = null;
		try {
			connection = connectionFactory.createConnection();
			connection.start();
			Session session = connection.createSession(true,
					Session.AUTO_ACKNOWLEDGE);

			Destination destination = session.createQueue(queueName);

			msgProd = session.createProducer(destination);
//			Thread.currentThread().getId()connection;
			TextMessage msg = session.createTextMessage("Hello,world");
			msgProd.send(msg);
			session.commit();
			

		} catch (Exception ex) {
			ex.printStackTrace();
		} finally {
			try {
				connection.close();
			} catch (Throwable ignore) {
			}
		}
	}

	public void SendMsg(String msg) {
	}

	public static void main(String args[]) {
		MsgProducer mp = new MsgProducer();
		mp.SendMsg();
	}

}
